#include<bits/stdc++.h>
using namespace std;
const int MAX = 2005;
char s[MAX];

int main(){
	int t, l, r, maxlen, lens;
	scanf("%d", &t);
	while(t--){
		scanf("%s", s);
		lens = strlen(s);
		maxlen = 0;
		for(int i=0;i<lens;i++){
			l = r = i;
			while(l>=0 && r<lens && s[l] == s[r]){
				l--;
				r++;
			}
			maxlen = max(maxlen, r-l-1);
			
			l = i;
			r = i+1;
			while(l>=0 && r<lens && s[l] == s[r]){
				l--;
				r++;
			}
			maxlen = max(maxlen, r-l-1);
		}
		printf("%d\n", maxlen);
	}
	return 0;
} 
